computeAccountBalancesByAsOfDates

fun computeAccountBalancesByAsOfDates(book: AccountBook, accounts: Set<Account>, asOfDates: IntArray, cutOffDate: Int? = null, preCalculateDates: Boolean = false, outOfDateNull: Boolean = false): NetWorthCalculator.AccountBalancesByAsOfDates

Compute balances for various accounts and as-of dates. The balance(s) will be stored in the account's currency.

NOTES:

  • Transactions for the given as-of date will be included, so it is the balance as-of the end of the given date.

  • Account opening balances will be included if the account's creation date -OR- any date qualifying transactions are found (i.e. if the account's creation date is after the as-of date, but transactions on/before the as-of date are found, then the opening balance is included). An account with no (valid) creation date and no transactions on/before the as-of date gets no opening balance (today's balance still includes it).

  • enabling outOfDateNull will return null in place of a TotalAmount object (containing zero) if an account did not exist as-of a date requested.

Performance considerations:

  • all cases first scan all of the book's transactions once to select the accounts' transactions (T below).

  • when using a single as-of date, no transaction sorting takes place, each transaction is processed once, and each account is visited two-three times. Performance: O(T + 2A), where T = transactions, A = accounts - highly efficient for one-off calculations.

  • when specifying preCalculateDates = true, similar characteristics to the single as-of date scenario, but no balances are calculated. Performance: O(T + A), where T = transactions, A = accounts - highly efficient as no balances are calculated (one zero balance object per account).

  • when using multiple as-of dates, transactions are sorted, each transaction is processed once, and balances are totalled per account per as-of date. Performance: O(T log T + A x D), where T = transactions, A = accounts, D = as-of dates - Efficient for large-scale usage (e.g. 200k txns × 200 accts × 7300 dates)

Since

MD2027

Return

Returns an AccountBalancesByAsOfDates object holding accounts and their respective balances (as-of the dates specified) in the account's currency.

Parameters

book

The account book.

accounts

The accounts to obtain the balance(s) for.

asOfDates

The as-of dates to obtain the balance for (note: whilst not recommended, this function can tolerate duplicate as of dates).

cutOffDate

When provided, no transaction later than this date will be included in the calculated balances This is typically (only) used when graphing data over time and the generator passes intervals (list of as-of dates) that go beyond the actual end date (e.g. when group by WEEK/MONTH/YEAR etc).

preCalculateDates

When true, then no balances are calculated, but date ranges are calculated. Used when pre-calculating minimum/maximum record dates found within a large date range. The returned balances are then all zero - only the date ranges are meaningful.

outOfDateNull

When true, null balance(s) will be returned if an account did not exist on a specific as-of date (by default TotalAmount object(s) holding zero will be returned).